$: << File.join(File.expand_path(File.dirname(__FILE__)), "..")

require 'rubygems'
require 'mapper/Normalizer'
require 'test/unit'

class MapperTest < Test::Unit::TestCase
	
	def test_nodup_sort
		data = [
			"hello\thello",	
			"hello hello\thello",
			"world hello\thello world",
			"hello 1234 world\t1234 hello world",
		]
	
		cls = Normalizer.new('--field 0:nodup,sort')
		counter = 0
		data.each{|row|
			expecting = row.split("\t")[1]
			output = cls.execute(row)
			found = output.split("\t")[0]
			assert_equal(expecting, found, "failed for #{row}: Expecting #{expecting} -- Found #{found}}")
		}		
	end
	
	def test_retain
		data = [
			"hello\thello",	
			"hello hello\thello",
			"world hello\thello world",
			"hello 1234 world\t1234 hello world",
		]
	
		cls = Normalizer.new('--field 0:nodup,sort --retain')
		counter = 0
		data.each{|row|
			expecting = row.split("\t")[1]
			output = cls.execute(row)
			found = output.split("\t")[2]
			assert_equal(expecting, found, "failed for #{row}: Expecting #{expecting} -- Found #{found}}")
		}		
	end
	
	def test_porter
		data = [
			"restaurants\trestaur",
			"indian\tindian",
			"indian restaurants\tindian restaur",
			"restaurant indians\trestaur indian"
		]
	
		cls = Normalizer.new('--field 0:downcase,alphanum,porter')
		counter = 0
		data.each{|row|
			output = cls.execute(row).split("\t")
			assert_equal(output[0], output[1], "failed for #{row[0]}: got #{output[0]}")
		}		
	end	
end